class_name Blackboard

const DEFAULT = "default"

var _data: Dictionary = {}

func init():
	_data[DEFAULT] = {}
	
func keys() -> Array[String]:
	var keys: Array[String]
	keys.assign(_data.keys().duplicate())
	return keys
func values() -> Array:
	var values: Array
	values.assign(_data.values().duplicate())
	return values

func create_blackboard_key(blackboard_name:String):
	if not _data.has(blackboard_name):
		_data[blackboard_name] = {}

func set_value(key: Variant, value: Variant, blackboard_name: String = DEFAULT):
	if not _data.has(blackboard_name):
		_data[blackboard_name] = {}

	_data[blackboard_name][key] = value


func get_value(key: Variant, default_value: Variant = null, blackboard_name: String = DEFAULT) -> Variant:
	if has_value(key, blackboard_name):
		return _data[blackboard_name].get(key, default_value)
	return default_value


func has_value(key: Variant, blackboard_name: String = DEFAULT) -> bool:
	return (
		_data.has(blackboard_name)
		and _data[blackboard_name].has(key)
		and _data[blackboard_name][key] != null
	)


func erase_value(key: Variant, blackboard_name: String = DEFAULT) -> void:
	if _data.has(blackboard_name):
		_data[blackboard_name][key] = null

func _init(init_data:Dictionary = {}) -> void:
	init()
	for key in init_data.keys():
		set_value(key,init_data[key])
